home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / bin / foo2zjs-wrapper < prev    next >
Text File  |  2008-09-09  |  18KB  |  727 lines

  1. #!/bin/sh
  2.  
  3. #* Copyright (C) 2003-2006  Rick Richardson
  4. #*
  5. #* This program is free software; you can redistribute it and/or modify
  6. #* it under the terms of the GNU General Public License as published by
  7. #* the Free Software Foundation; either version 2 of the License, or
  8. #* (at your option) any later version.
  9. #*
  10. #* This program is distributed in the hope that it will be useful,
  11. #* but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #* GNU General Public License for more details.
  14. #*
  15. #* You should have received a copy of the GNU General Public License
  16. #* along with this program; if not, write to the Free Software
  17. #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. #*
  19. #* Authors: Rick Richardson <rick.richardson@comcast.net>
  20.  
  21. VERSION='$Id: foo2zjs-wrapper.in,v 1.115 2007/12/27 06:44:13 rick Exp $'
  22.  
  23. #
  24. # Printer Notes:
  25. #
  26. # Minolta/QMS 2300 DL    - Does not need clipping, -X16, or -P.  But it doesn't
  27. #              break anything if you use them.
  28. #
  29. # Minolta/QMS 2200 DL    - Requires -X16 (which is on by default)
  30. #            - Requires clipping
  31. #
  32. # HP LaserJet 1000    - Same as 2200 DL, plus needs -P
  33. # HP LaserJet 1005    - Same as 2200 DL, plus needs -P
  34. # HP LaserJet 1018    - Same as 2200 DL, plus needs -P -z1 -L0
  35. # HP LaserJet 1020    - Same as 2200 DL, plus needs -P -z1 -L0
  36. #
  37.  
  38. PROGNAME="$0"
  39. BASENAME=`basename $PROGNAME`
  40. PREFIX=/usr
  41. SHARE=$PREFIX/share/foo2zjs
  42. PATH=$PATH:/sw/bin:/opt/local/bin
  43.  
  44. #
  45. #    Log the command line, for debugging and problem reports
  46. #
  47. if [ -x /usr/bin/logger ]; then
  48.     logger -t "$BASENAME" -p lpr.info -- "$BASENAME $@" </dev/null
  49. fi
  50.  
  51. usage() {
  52.     cat <<EOF
  53. Usage:
  54.     $BASENAME [options] [ps-file]
  55.  
  56.     Foomatic printer wrapper for the foo2zjs printer driver.
  57.     This script reads a Postscript ps-file or standard input
  58.     and converts it to Zenographics ZjStream printer format.
  59.  
  60. Normal Options:
  61. -c                Print in color (else monochrome)
  62. -d duplex         Duplex code to send to printer [$DUPLEX]
  63.                     1=off, 2=longedge, 3=shortedge
  64. -m media          Media code to send to printer [$MEDIA]
  65.                     1=standard, 2=transparency, 3=glossy, 257=envelope,
  66.                     259=letterhead, 261=thickstock, 262=postcard, 263=labels
  67. -p paper          Paper code [$PAPER]
  68.                     1=letter, 5=legal, 7=executive, 9=A4, 11=A5, 13=B5
  69.                     20=env#10, 27=envDL 28=envC5 34=envB5 37=envMonarch
  70. -n copies         Number of copies [$COPIES]
  71. -r <xres>x<yres>  Set device resolution in pixels/inch [$RES]
  72. -s source         Source code to send to printer [$SOURCE]
  73.                     1=upper, 2=lower, 4=manual, 7=auto
  74.             Code numbers may vary with printer model.
  75. -t                Draft mode.  Every other pixel is white.
  76. -2/-3/-4/-6/-8/-10/-12/-14/-15/-16/-18
  77.                   Print with N-up (requires psutils)
  78. -o orient         For N-up: -op is portrait, -ol is landscape, -os is seascape.
  79.  
  80. Printer Tweaking Options:
  81. -u <xoff>x<yoff>  Set offset of upper left printable in pixels [varies]
  82. -l <xoff>x<yoff>  Set offset of lower right printable in pixels [varies]
  83. -L mask           Send logical clipping values from -u/-l in ZjStream [3]
  84.                   0=no, 1=Y, 2=X, 3=XY
  85. -P                Do not output START_PLANE codes.  May be needed by some
  86.                   monochrome-only printers.
  87. -X padlen         Add extra zero padding to the end of BID segments [16]
  88. -z model          Model: 0=2300DL 1=hp1020 [0]
  89.  
  90. Color Tweaking Options:
  91. -g gsopts         Additional options to pass to Ghostscript, such as
  92.                   -dDITHERPPI=nnn, etc.  May appear more than once. []
  93. -G profile.icm    Convert profile.icm to a Postscript CRD using icc2ps and
  94.                   adjust colors using the setcolorrendering PS operator.
  95.                   $SHARE/icm/ will be searched for profile.icm.
  96. -I intent         Select profile intent from ICM file [$INTENT]
  97.                   0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute
  98. -G gamma-file.ps  Prepend gamma-file to the Postscript input to perform
  99.                   color correction using the setcolortransfer PS operator.
  100.  
  101. Debugging Options:
  102. -S plane          Output just a single color plane from a color print [all]
  103.                   1=Cyan, 2=Magenta, 3=Yellow, 4=Black
  104. -D lvl            Set Debug level [$DEBUG]
  105. -V                $VERSION
  106. EOF
  107.  
  108.     exit 1
  109. }
  110.  
  111. #
  112. #       Report an error and exit
  113. #
  114. error() {
  115.     echo "$BASENAME: $1" >&2
  116.     exit 1
  117. }
  118.  
  119. dbgcmd() {
  120.     if [ $DEBUG -ge 1 ]; then
  121.         echo "$@" >&2
  122.     fi
  123.     "$@"
  124. }
  125.  
  126. #
  127. #    N-up-ify the job.  Requires psnup from psutils package
  128. #
  129. nup() {
  130.     case "$NUP" in
  131.     [2368]|1[0458])
  132.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.3in -p$paper -q
  133.     ;;
  134.     [49]|1[26])
  135.     tr '\r' '\n' | psnup $NUP_ORIENT -d2 -$NUP -m.5in -p$paper -q
  136.     ;;
  137.     *)
  138.     error "Illegal call to nup()."
  139.     ;;
  140.     esac
  141. }
  142.  
  143. #
  144. #       Process the options
  145. #
  146.  
  147. # Try to use a local copy of GhostScript 8.54, if available.  Otherwise,
  148. # fallback to whatever the Linux distro has installed (usually 7.07)
  149. #
  150. # N.B. := operator used here, when :- would be better, because "ash"
  151. # doesn't have :-
  152. if gs.foo -v >/dev/null 2>&1; then
  153.         GSBIN=${GSBIN:-gs.foo}
  154. else
  155.         GSBIN=${GSBIN:-gs}
  156. fi
  157.  
  158. CMDLINE="$*"
  159. DEBUG=0
  160. DUPLEX=1
  161. COLOR=
  162. COLORMODE=default
  163. MODEL=0
  164. QUALITY=wts
  165. MEDIA=1
  166. COPIES=1
  167. test -r /etc/papersize && PAPER=$(cat /etc/papersize)
  168. test "$PAPER" || PAPER=1
  169. RES=1200x600
  170. SOURCE=7
  171. NUP=
  172. CLIP_UL=
  173. CLIP_LR=
  174. CLIP_LOG=
  175. BC=
  176. AIB=
  177. NOPLANES=
  178. COLOR2MONO=
  179. GAMMAFILE=
  180. INTENT=0
  181. GSOPTS=
  182. EXTRAPAD=
  183. SAVETONER=
  184. NUP_ORIENT=
  185. GSDEV=-sDEVICE=pbmraw
  186. # What mode to use if the user wants us to pick the "best" mode
  187. case `$GSBIN --version` in
  188. 7*)    DEFAULTCOLORMODE=10
  189.     DEFAULTCOLORMODE=2
  190.     ;;
  191. 8.1*)
  192.     DEFAULTCOLORMODE=2
  193.     QUALITY=1
  194.     ;;
  195. *)    DEFAULTCOLORMODE=2
  196.     ;;
  197. esac
  198. while getopts "1:23456789o:b:cC:d:g:l:u:L:m:n:p:q:r:s:tz:ABS:D:G:I:PX:Vh?" opt
  199. do
  200.     case $opt in
  201.     b)    GSBIN="$OPTARG";;
  202.     c)    COLOR=-c;;
  203.     d)    DUPLEX="$OPTARG";;
  204.     g)    GSOPTS="$GSOPTS $OPTARG";;
  205.     m)    MEDIA="$OPTARG";;
  206.     n)    COPIES="$OPTARG";;
  207.     p)    PAPER="$OPTARG";;
  208.     q)    QUALITY="$OPTARG";;
  209.     r)    RES="$OPTARG";;
  210.     s)    SOURCE="$OPTARG";;
  211.     t)    SAVETONER="-t";;
  212.     z)    MODEL="$OPTARG";;
  213.     l)    CLIP_LR="-l $OPTARG";;
  214.     u)    CLIP_UL="-u $OPTARG";;
  215.     L)    CLIP_LOG="-L $OPTARG";;
  216.     A)    AIB=-A;;
  217.     B)    BC=-B;;
  218.     C)    COLORMODE="$OPTARG";;
  219.     S)    COLOR2MONO="-S$OPTARG";;
  220.     D)    DEBUG="$OPTARG";;
  221.     G)    GAMMAFILE="$OPTARG";;
  222.     I)    INTENT="$OPTARG";;
  223.     P)    NOPLANES=-P;;
  224.     X)    EXTRAPAD="-X $OPTARG";;
  225.     [234689])    NUP="$opt";;
  226.     [57])    error "Can't find acceptable layout for $opt-up";;
  227.     1)    case "$OPTARG" in
  228.         [024568])    NUP="1$OPTARG";;
  229.         *)    error "Can't find acceptable layout for 1$OPTARG-up";;
  230.         esac
  231.         ;;
  232.     o)    case "$OPTARG" in
  233.         l*)    NUP_ORIENT=-l;;
  234.         s*)    NUP_ORIENT=-r;;
  235.         p*|*)    NUP_ORIENT=;;
  236.         esac;;
  237.     V)    echo "$VERSION"; foo2zjs -V; foo2zjs-pstops -V; exit 0;;
  238.     h|\?)
  239.         if [ "$CMDLINE" != "-?" -a "$CMDLINE" != -h ]; then
  240.             echo "Illegal command:"
  241.             echo "    $0 $CMDLINE"
  242.             echo
  243.         fi
  244.         usage;;
  245.     esac
  246. done
  247. shift `expr $OPTIND - 1`
  248.  
  249. #
  250. # If there is an argument left, take it as the file to print.
  251. # Else, the input comes from stdin.
  252. #
  253. if [ $# -ge 1 ]; then
  254.     if [ "$LPJOB" = "" ]; then
  255.     : # LPJOB="$1"
  256.     fi
  257.     exec < $1
  258. fi
  259.  
  260. #
  261. case "$QUALITY" in
  262. 0)
  263.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  264.     ;;
  265. 1)
  266.     GSOPTS="-dCOLORSCREEN $GSOPTS"
  267.     ;;
  268. 2)
  269.     GSOPTS="-dMaxBitmap=500000000 $GSOPTS"
  270.     ;;
  271. wts)
  272.     GSOPTS="-dCOLORSCREEN -dMaxBitmap=500000000 $GSOPTS"
  273.     ;;
  274. esac
  275.  
  276. #
  277. #    Validate model code
  278. #
  279. case "$MODEL" in
  280. 0|1)    ;;
  281. *)    error "Unknown model code $MODEL";;
  282. esac
  283.  
  284. #
  285. #    Validate media code
  286. #
  287. case "$MEDIA" in
  288. 1|standard)    MEDIA=1;;
  289. 2|transparency)    MEDIA=2;;
  290. 3|glossy)    MEDIA=3;;
  291. 257|envelope)    MEDIA=257;;
  292. 259|letterhead)    MEDIA=259;;
  293. 261|thickstock)    MEDIA=261;;
  294. 262|postcard)    MEDIA=262;;
  295. 263|labels)    MEDIA=263;;
  296. [0-9]*)        ;;
  297. *)        error "Unknown media code $MEDIA";;
  298. esac
  299.  
  300. #
  301. #    Validate source (InputSlot) code
  302. #
  303. case "$SOURCE" in
  304. 1|upper)    SOURCE=1;;
  305. 2|lower)    SOURCE=2;;
  306. 4|manual)    SOURCE=4;;
  307. 7|auto)        SOURCE=7;;
  308. [0-9]*)        ;;
  309. *)        error "Unknown source code $SOURCE";;
  310. esac
  311.  
  312. #
  313. #    Validate Duplex code
  314. #
  315. case "$DUPLEX" in
  316. 1|off|none)    DUPLEX=1;;
  317. 2|long*)    DUPLEX=2;;
  318. 3|short*)    DUPLEX=3;;
  319. [0-9]*)        ;;
  320. *)        error "Unknown duplex code $DUPLEX";;
  321. esac
  322.  
  323. #
  324. #    Validate Resolution
  325. #
  326. case "$RES" in
  327. 600x600)    ;;
  328. 1200x600)    ;;
  329. 2400x600)    ;;
  330. *)        error "Illegal resolution $RES";;
  331. esac
  332.  
  333. #
  334. #    Figure out the paper dimensions in pixels/inch, and set the
  335. #    default clipping region.  Unfortunately, this is a trouble
  336. #    area for ZjStream printers.  Various versions of ZjS print
  337. #    engines react differently when asked to print into their
  338. #    unprintable regions.
  339. #
  340. #    The Minolta 2200 DL is sensitive to its unprintable regions,
  341. #    and will pixel skew if you try to print there.
  342. #
  343. #    The HP1000 will print blank pages when asked to print into its
  344. #    unprintable region.
  345. #
  346. #    The Minolta 2300 DL doesn't care if print into the unprintable
  347. #    region.  It will do the clipping itself.  This is as it should be.
  348. #    But it won't hurt it if we do the clipping here.
  349. #
  350. set_clipping() {
  351.     ulx=$1; uly=$2
  352.     lrx=$3; lry=$4
  353.  
  354.     # Set clipping region if it isn't already set
  355.     if [ "$CLIP_UL" = "" ]; then
  356.     case "$RES" in
  357.     600x600)    ulx=`expr $ulx / 2`;;
  358.     2400x600)    ulx=`expr $ulx \* 2`;;
  359.     esac
  360.     CLIP_UL="-u ${ulx}x${uly}"
  361.     fi
  362.     if [ "$CLIP_LR" = "" ]; then
  363.     case "$RES" in
  364.     600x600)    lrx=`expr $lrx / 2`;;
  365.     2400x600)    lrx=`expr $lrx \* 2`;;
  366.     esac
  367.     CLIP_LR="-l ${lrx}x${lry}"
  368.     fi
  369. }
  370.  
  371. case "$PAPER" in
  372. Custom*)
  373.         #%%BeginFeature: *CustomPageSize True
  374.         #216
  375.         #360
  376.         #0
  377.         #0
  378.         #0
  379.         #pop pop pop pop pop
  380.  
  381.         #%%BeginFeature: *CustomPageSize True
  382.         #792.000000 612.000000 1 0.000000 0.000000
  383.         #pop pop pop pop pop
  384.  
  385.         if [ $DEBUG = 0 ]; then
  386.             TMPFILE=/tmp/cus$$
  387.         else
  388.             TMPFILE=/tmp/custom.ps
  389.         fi
  390.         cat >$TMPFILE
  391.         exec <$TMPFILE
  392.  
  393.         tmp=`head -n 10000 $TMPFILE \
  394.             | sed -n '/CustomPageSize/{n;p;n;p;}' \
  395.             | tr '\n' ' '`
  396.         case "$tmp" in
  397.         [0-9]*\ [0-9]*)
  398.             XDIM=`echo "$tmp" | sed 's/ .*//'`
  399.             YDIM=`echo "$tmp" | sed -e 's/^[^ ]* //' -e 's/ .*//'`
  400.             ;;
  401.         *)
  402.             if [ $DEBUG = 0 ]; then rm -f $TMPFILE; fi
  403.             error "Custom page size [XY]DIM != 1-99999"
  404.             ;;
  405.         esac
  406.         XDIM=`dc -e "$XDIM 1200* 72/p"`
  407.         YDIM=`dc -e "$YDIM 600* 72/p"`
  408.         PAPER=256;        paper=letter;
  409.         MEDIA=261
  410.                 set_clipping 2 100     2 100
  411.         ;;
  412. 1|letter)    PAPER=1;    paper=letter;    XDIM="10200"; YDIM="6600"
  413.         case "$MODEL" in
  414.         0)    set_clipping 204 102    204 106;;
  415.         1)    set_clipping 192 96    192 96;;
  416.         # 1)    set_clipping 96 96    288 96;;
  417.         esac
  418.         ;;
  419. 5|legal)    PAPER=5;    paper=legal;     XDIM="10200"; YDIM="8400"
  420.         case "$MODEL" in
  421.         0)    set_clipping 204 102    204 106;;
  422.         1)    set_clipping 192 96    192 96;;
  423.         esac
  424.         ;;
  425. 7|executive)    PAPER=7;    paper=executive; XDIM="8700";  YDIM="6300"
  426.         case "$MODEL" in
  427.         0)    set_clipping 206 102    206 102;;
  428.         1)    set_clipping 192 96    192 96;;
  429.         esac
  430.         ;;
  431. 9|a4|A4)    PAPER=9;    paper=a4;        XDIM="9920";  YDIM="7016"
  432.         case "$MODEL" in
  433.         0)
  434.             if [ "$NOPLANES" != "" -a "$RES" = 600x600 ]; then
  435.             # Hack fix for LJ1000
  436.             set_clipping 224 100    224 100
  437.             else
  438.             # 2200DL
  439.             set_clipping 200 100    200 100
  440.             fi
  441.             ;;
  442.         1)    set_clipping 192 96    192 96;;
  443.         esac
  444.         ;;
  445. 11|a5|A5)    PAPER=11;    paper=a5;        XDIM="6992";  YDIM="4960"
  446.         case "$MODEL" in
  447.         0)    set_clipping 200 100    200 100;;
  448.         1)    set_clipping 192 96    192 96;;
  449.         esac
  450.         ;;
  451. 13|b5|B5)    PAPER=13;    paper=b5;        XDIM="8598";  YDIM="6070"
  452.         case "$MODEL" in
  453.         0)    set_clipping 207 107    207 107;;
  454.         1)    set_clipping 192 96    192 96;;
  455.         esac
  456.         ;;
  457. 20|"env#10")    PAPER=20;    paper=env10;     XDIM="4950";  YDIM="5700"
  458.         case "$MODEL" in
  459.         0)    set_clipping 171 78    171 78;;
  460.         1)    set_clipping 171 78    171 78;;
  461.         esac
  462.         ;;
  463. 27|envDL)    PAPER=27;    paper=envDL;     XDIM="5200";  YDIM="5200"
  464.         case "$MODEL" in
  465.         0)    set_clipping 176 84    176 84;;
  466.         1)    set_clipping 176 84    176 84;;
  467.         esac
  468.         ;;
  469. 28|envC5)    PAPER=28;    paper=envC5;     XDIM="7650";  YDIM="5408"
  470.         case "$MODEL" in
  471.         0)    set_clipping 170 80    169 80;;
  472.         1)    set_clipping 170 80    169 80;;
  473.         esac
  474.         ;;
  475. 34|envB5)    PAPER=34;    paper=envB5;     XDIM="8316";  YDIM="5892"
  476.         case "$MODEL" in
  477.         0)    set_clipping 174 74    174 74;;
  478.         1)    set_clipping 174 74    174 74;;
  479.         esac
  480.         ;;
  481. 37|envMonarch)    PAPER=37;    paper=envMonarch;XDIM="4650";  YDIM="4500"
  482.         case "$MODEL" in
  483.         0)    set_clipping 174 78    173 78;;
  484.         1)    set_clipping 174 78    173 78;;
  485.         esac
  486.         ;;
  487. *)        error "Unimplemented paper code $PAPER";;
  488. esac
  489. # e.g. /usr/share/ghostscript/7.07/lib/gs_statd.ps
  490. PAPERSIZE="-sPAPERSIZE=$paper";
  491.  
  492. case "$RES" in
  493. 600x600)    XDIM=`expr $XDIM / 2`;;
  494. 1200x600)    ;;
  495. 2400x600)    XDIM=`expr $XDIM \* 2`;;
  496. esac
  497. DIM="${XDIM}x${YDIM}"
  498.  
  499. #
  500. # Filter thru psnup if N-up printing has been requested
  501. #
  502. case $NUP in
  503. [234689]|1[024568])    PREFILTER="nup";;
  504. *)            PREFILTER=cat;;
  505. esac
  506. if [ "$DEBUG" -ge 9 ]; then
  507.     PREFILTER="tee /tmp/$BASENAME.ps"
  508. fi
  509.  
  510. #
  511. #    Overload -G.  If the file name ends with ".icm" or ".ICM"
  512. #    then convert the ICC color profile to a Postscript CRD,
  513. #    then prepend it to the users job.  Select the intent
  514. #    using the -I option.
  515. #
  516.  
  517. create_crd() {
  518.     #
  519.     # Create a Postscript CRD
  520.     #
  521.     ICC2PS=$PREFIX/bin/foo2zjs-icc2ps
  522.     if [ -x $ICC2PS ]; then
  523.     case "$GAMMAFILE" in
  524.     none | none.icm | */none.icm)
  525.         ;;
  526.     *)
  527.     $ICC2PS -o $GAMMAFILE -t$INTENT > $ICCTMP.crd.ps 2>$ICCTMP.log \
  528.     || error "Problem converting .ICM file to Postscript"
  529.         ;;
  530.     esac
  531.  
  532.     PSTOPS_OPTS="$PSTOPS_OPTS -c"
  533.     cat > $ICCTMP.usecie.ps <<-EOF
  534.         %!PS-Adobe-3.0
  535.         <</UseCIEColor true>>setpagedevice
  536.     EOF
  537.     if [ "$QUALITY" = wts ]; then
  538.         cat >> $ICCTMP.usecie.ps <<-EOF
  539.         << /UseWTS true >> setuserparams
  540.         <<
  541.             /AccurateScreens true
  542.             /HalftoneType 1
  543.             /HalftoneName (Round Dot Screen) cvn
  544.             /SpotFunction { 180 mul cos exch 180 mul cos add 2 div}
  545.             /Frequency 137
  546.             /Angle 37
  547.         >> sethalftone
  548.         EOF
  549.     fi
  550.     cat > $ICCTMP.selcrd.ps <<-EOF
  551.         /Current /ColorRendering findresource setcolorrendering
  552.     EOF
  553.     case "$GAMMAFILE" in
  554.     none | none.icm | */none.icm) GAMMAFILE="$ICCTMP.usecie.ps";;
  555.     *)    GAMMAFILE="$ICCTMP.usecie.ps $ICCTMP.crd.ps $ICCTMP.selcrd.ps";;
  556.     esac
  557.     else
  558.     GAMMFILE=
  559.     fi
  560. }
  561.  
  562. if [ $DEBUG -gt 0 ]; then
  563.     ICCTMP=/tmp/icc
  564. else
  565.     ICCTMP=/tmp/icc$$
  566. fi
  567.  
  568. if [ "" = "$COLOR" ]; then
  569.     COLORMODE=
  570.     GAMMAFILE=
  571. else
  572.     case "$COLORMODE" in
  573.     default)    COLORMODE=$DEFAULTCOLORMODE;;
  574.     esac
  575.     case "$GAMMAFILE" in
  576.     default)    GAMMAFILE=DL2312.icm;;
  577.     esac
  578. fi
  579.  
  580. CRDBASE="$PREFIX/share/foo2zjs/crd"
  581. case "$RES" in
  582.     600x600)    SCREEN=screen1200.ps;;
  583.     1200x600)    SCREEN=screen1200.ps;;
  584.     2400x600)    SCREEN=screen2400.ps;;
  585. esac
  586.  
  587. PSTOPS_OPTS="-n"
  588.  
  589. case "$COLORMODE" in
  590. 0|"")
  591.     # Monochrome
  592.     ;;
  593. 10|icm)
  594.     # Use old ICM method
  595.     AIB=-A
  596.     BC=-B
  597.     case "$GAMMAFILE" in
  598.     none | none.icm | */none.icm)
  599.     create_crd
  600.     ;;
  601.     *.icm|*.ICM|*.icc|*.ICC)
  602.     #
  603.     # Its really an .ICM file, not a gamma file.
  604.     #
  605.     # The file can be a full path name, or the name of a file in $SHARE/icm/
  606.     #
  607.     if [ -r "$GAMMAFILE" ]; then
  608.         create_crd
  609.     elif [ -r "$SHARE/icm/$GAMMAFILE" ]; then
  610.         GAMMAFILE="$SHARE/icm/$GAMMAFILE"
  611.         create_crd
  612.     else
  613.         GAMMAFILE=
  614.     fi
  615.     ;;
  616.     esac
  617.     ;;
  618. 1|photo)
  619.     # Photo
  620.     GAMMAFILE="$CRDBASE/prolog.ps"
  621.     GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr125,75-per.crd"
  622.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  623.     ;;
  624. 2|graphics)
  625.     # Photo and Text
  626.     GAMMAFILE="$CRDBASE/prolog.ps"
  627.     #GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,75-per.crd"
  628.     GAMMAFILE="$GAMMAFILE $CRDBASE/kh.crd"
  629.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  630.     ;;
  631. 3|text)
  632.     # Graphic and Text
  633.     GAMMAFILE="$CRDBASE/prolog.ps"
  634.     #GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,50-per.crd"
  635.     GAMMAFILE="$GAMMAFILE $CRDBASE/kx.crd"
  636.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  637.     ;;
  638. 4|tonersave)
  639.     # Reduced toner
  640.     GAMMAFILE="$CRDBASE/prolog.ps"
  641.     GAMMAFILE="$GAMMAFILE $CRDBASE/2300w-1200@150-l250-kx,ucr100,0-per.crd"
  642.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  643.     ;;
  644. *.crd)
  645.     GAMMAFILE="$CRDBASE/prolog.ps"
  646.     if [ -f $COLORMODE ]; then
  647.     GAMMAFILE="$GAMMAFILE $COLORMODE"
  648.     elif [ -f $CRDBASE/$COLORMODE ]; then
  649.     GAMMAFILE="$GAMMAFILE $CRDBASE/$COLORMODE"
  650.     else
  651.     error "Can't find CRD '$COLORMODE' in . or in $CRDBASE"
  652.     fi
  653.     GAMMAFILE="$GAMMAFILE $CRDBASE/$SCREEN"
  654.     ;;
  655. *)
  656.     error "Unknown color method '$COLORMODE'"
  657.     ;;
  658. esac
  659.  
  660. if [ "$COLOR" != "" -a "$QUALITY" = wts ]; then
  661.     PSTOPS_OPTS="$PSTOPS_OPTS -w"
  662. fi
  663.  
  664. if [ "" != "$COLOR" ]; then
  665.     if [ "" = "$AIB" -a "" = "$BC" ]; then
  666.     # Faster, but can't handle AllIsBlack or BlackClears
  667.     GSDEV=-sDEVICE=pksmraw
  668.     else
  669.     # Can't handle different size pages
  670.     GSDEV=-sDEVICE=bitcmyk
  671.     fi
  672. fi
  673.  
  674. #
  675. #    Figure out USERNAME
  676. #
  677. if [ "$LPUSER" != "" ]; then
  678.     USER="$LPUSER@$LPHOST"
  679. else
  680.     USER=""
  681. fi
  682.  
  683. #
  684. #    Main Program, just cobble together the pipeline and run it
  685. #
  686. #    The malarky with file descriptors 1 and 3 is to avoid a bug in
  687. #    (some versions?) of Ghostscript where Postscript's stdout gets
  688. #    intermingled with the printer drivers output, resulting in
  689. #    corrupted image data.
  690. #
  691. GS="$GSBIN -q -dBATCH -dSAFER -dQUIET -dNOPAUSE"
  692.  
  693. foo2zjs-pstops $PSTOPS_OPTS | \
  694. $PREFILTER \
  695. | ($GS $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS \
  696.     -sOutputFile="|cat 1>&3" $GAMMAFILE -_ >/dev/null) 3>&1 \
  697. | foo2zjs -r$RES -g$DIM -p$PAPER -m$MEDIA -n$COPIES -d$DUPLEX -s$SOURCE \
  698.         -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG $SAVETONER \
  699.         -J "$LPJOB" -U "$USER" \
  700.         $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD -D$DEBUG
  701.  
  702. #
  703. #    Log the command line, for debugging and problem reports
  704. #
  705. if [ -x /usr/bin/logger ]; then
  706.     logger -t "$BASENAME" -p lpr.info -- \
  707.     "$GSBIN $PAPERSIZE -g$DIM -r$RES $GSDEV $GSOPTS $GAMMAFILE"
  708.     logger -t "$BASENAME" -p lpr.info -- \
  709.     "foo2zjs -r$RES -g$DIM -p$PAPER -m$MEDIA \
  710. -n$COPIES -d$DUPLEX -s$SOURCE -z$MODEL $COLOR $CLIP_UL $CLIP_LR $CLIP_LOG \
  711. $SAVETONER $BC $AIB $COLOR2MONO $NOPLANES $EXTRAPAD"
  712. fi
  713.  
  714. #
  715. #    Remove cruft
  716. #
  717. if [ $DEBUG -eq 0 ]; then
  718.     for i in crd.ps log usecie.ps selcrd.ps
  719.     do
  720.     file="$ICCTMP.$i"
  721.     [ -f $file ] && rm -f $file
  722.     done
  723.     [ -f "$TMPFILE" ] && rm -f $TMPFILE
  724. fi
  725.  
  726. exit 0
  727.